<template>
  <div class="container">
    <div class="nav-bar flex">
      <div :class="{active:currentType==-1}">全部</div>
      <div class="rel">按时间
          <input type="month" @change="changeTime" v-model="time" class="full-opacity">
      </div>
      <div @click="showFilterDialog" :class="{active:currentType>=0}">按分类</div>
    </div>
    <div class="nav-bar-before"></div>
    <xd-datalist url="/api/bill/my_costs" ref="datalist">
      <template slot-scope="scope">
        <div class="p1 border-b" v-for="(item,index) in scope.list" :key="index" @click="gotoDetail(item)">
          <div class="flex">
            <div>
              <img src="../../assets/icons/cost/oil.png" alt="" v-if="item.type=='oil'">
              <img src="../../assets/icons/cost/shop.png" alt="" v-else-if="item.type=='shop'">
              <img src="../../assets/icons/cost/gift.png" alt="" v-else-if="item.type=='gift'">
            </div>
            <div class="flex-con pl29">
              <div class="fz28 txt333 cost-title">
                {{item.title}}
              </div>
              <div class="txt333 fz22 pt20">
                {{item.costTime|parseTime}}
              </div>
            </div>
            <div class="points" :class="item.points<0?'add-points':'reduce-points'">
              {{item.points>0?'-'+item.points+'积分':''}}
              {{item.money>0?'-'+item.money+'元':''}}
            </div>
          </div>
        </div>
      </template>
    </xd-datalist>

    <div class="typefilter-masker" v-show="isFilterDialogShowed" @click="hideFilterDialog">
      <div class="typefilter-dialog" @click.stop="noop">
        <div class="typefilter-title border-b">
          选择交易类型
          <img src="../../assets/icons/cost/closegray@2x.png" alt="" class="closegray-icon" @click="hideFilterDialog">
        </div>
        <div class="p2 flex">
          <img src="../../assets/icons/cost/yzjy.png" alt="" class="yzjy-icon" @click="toggleType(1)">
          <img src="../../assets/icons/cost/lpdh.png" alt="" class="yzjy-icon" @click="toggleType(2)">
          <img src="../../assets/icons/cost/pointsshop.png" alt="" class="yzjy-icon" @click="toggleType(0)">
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentType:0,
      time: "",
      isFilterDialogShowed: false,
      list: []
    };
  },
  created() {},
  methods: {
    changeTime() {
      this.$refs.datalist.addParam("time", this.time).refresh();
    },
    gotoDetail(item) {
      // this.$router.push('/costdetail?id='+item.id);
    },
    noop() {},
    toggleType(t) {
      this.currentType = t;
      this.$refs.datalist.addParam("type", t).refresh();
      this.isFilterDialogShowed = false;
    },
    showFilterDialog() {
      this.isFilterDialogShowed = true;
    },
    hideFilterDialog() {
      this.isFilterDialogShowed = false;
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../../styles/nav";
.nav-bar-before {
  margin-bottom: 0.32rem;
}

.p1 {
  padding: 0.3467rem 0.4rem;
  img {
    width: 0.9067rem;
    height: 0.9067rem;
  }
  .pl29 {
    padding-left: 0.3867rem;
  }
  .points {
    font-size: 0.36rem;
  }
  .pt20 {
    padding-top: 0.2667rem;
  }
  .add-points {
    color: #ff2a2a;
  }
  .reduce-points {
    color: rgba(51, 51, 51, 0.26);
  }
}
.cost-title {
  line-height: 1.4em;
}

.typefilter-masker {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  background-color: rgba(0, 0, 0, 0.36);
  .typefilter-dialog {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ffffff;
    .typefilter-title {
      font-size: 0.4267rem;
      color: #333333;
      text-align: center;
      padding: 0.3733rem 0;
      position: relative;
      .closegray-icon {
        position: absolute;
        width: 0.5067rem;
        height: 0.5067rem;
        top: 0.3333rem;
        right: 0.4rem;
      }
    }
  }
  .p2 {
    padding: 0.5333rem 0.44rem 1.76rem 0.44rem;
    justify-content: space-between;
    img {
      width: 2.6rem;
      height: 0.8533rem;
    }
  }
}
</style>
